<template>
	<view class="location">
		<view class="location_info">
			<view class="location_info_people">
				<span>收件人</span><input v-model="GitList.realName" />
			</view>
			<view class="location_info_people">
				<span>手机号</span><input v-model="GitList.phone" />
			</view>
			<view class="location_info_people" @click="ClickLocation()">
				<span>所在地区</span><input v-model="GitList.provinceCityDistrict" />
			</view>
			<view class="location_info_people">
				<span>详细地址</span><input v-model="GitList.detail" />
			</view>
			<!-- <view class="location_info_people">
				<span>邮政编码</span><input v-model="GitList.postCode" />
			</view> -->
			
		</view>
		<view class="mr_scope">
			<span>设为默认地址</span><u-switch  v-model="CheckValue" activeColor="#88A58A" @change="change"></u-switch>
		</view>
		<u-popup :show="show" @close="close()">
			<view class="info">
				<scroll-view class="scroll" scroll-y="true">
					<view v-for="item in columns" @click="clickCname(item)" class="scroll_view">
						{{item.cname}}
					</view>
				</scroll-view>
			</view>
		</u-popup>
		<u-button type="success" shape="circle" text="修改" @click="Getlocation()"></u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				locationL: '',
				index:0,
				columns: [],
				show: false,
				visible:false,
				tabTitle: ['请选择'],
				locationValue: '',
				CheckValue:false,
				GitList:{
					realName:'',
					phone:'',
					provinceCityDistrict:'',
					detail:'',
					postCode:''
				}
			}
		},
		methods: {
			Getlocation(){
				this.$http({
					url:'/crmUserAddress/updCrmUserAddress',
					data:this.GitList
				}).then(res=>{
					if(res.data.code === 200){
						uni.showToast({
							title:'修改成功',
						})
						uni.navigateBack()
						
					}else{
						uni.showToast({
							title:'修改失败',
							icon:'error'
						})
					}
				})
				
			},
			change(e) {
				console.log('change', e);
				if(e===true){
					this.GitList.isDefault = 1
				}else{
					this.GitList.isDefault = 0
				}
			},
			clickCname(item) {
				console.log(this.index);
				if (this.index>1) {
					this.GitList.provinceCityDistrict = this.GitList.provinceCityDistrict + item.cname
				}else {
					this.GitList.provinceCityDistrict = item.cname
				}
				
				this.SearchLocation(item.id)
				this.GitList.cityId = item.id
				console.log(item.id)
				console.log(this.GitList.provinceCityDistrict)
			},
			SearchLocation(id) {
				this.$http({
					url: '/area/selectArea',
					method: 'GET',
					data: {
						parentId: id,
					}
				}).then(res => {
					this.columns = res.data.data
					if (this.columns.length == 0) {
						this.show = false
						this.index = 0
					}else {
						this.index++
					}
				})
			},
			ClickLocation() {
				this.show = true
				this.GitList.province = ''
				this.SearchLocation(1)
			},
			close() {
				this.show = false
			},
			SearchData(id){
				this.$http({
					url:'/crmUserAddress/selUpdAddress',
					data:{
						id:id
					},
					method:'GET'
				}).then(res=>{
					this.GitList = res.data.data
					if(res.data.data.isDefault == 1){
						this.CheckValue= true
					}else{
						this.CheckValue = false
					}
					if (res.data.data.provinceCityDistrict) {
						this.index = 0
					}
				})
			}
		},
		onLoad(option) {
			this.SearchData(option.id)
		}
	}
</script>

<style>
	@import './index';
</style>
